﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using HA.ModFlow.Controls;
using System.Windows;

using HA.ModFlow.Controls.Windows;

using HAUtilWpf.windows;
using HA.ModFlow.Domain.DomainLayer;
using System.Runtime.InteropServices;
namespace HA.ModFlow.Application
{
    public class CommandModule
    {
        protected CommandModule()
        {

        }

        static CommandModule defaultBinder;

        public static CommandModule DefaultBinder
        {
            get
            {

                if (defaultBinder == null)
                {
                    defaultBinder = new CommandModule();

                }
                return CommandModule.defaultBinder;
            }

        }



        public static Window mainWindow;



        /// <summary>
        /// 将命令绑定到窗体
        /// </summary>
        /// <param name="window"></param>
        public void BindCommandsToWindow(Window window)
        {
            //绑定NewProject命令
            CommandBinding cbNew = new CommandBinding();
            cbNew.Command = AppCommands.NewProject;
            cbNew.CanExecute += new CanExecuteRoutedEventHandler(cbNew_CanExecute);
            cbNew.Executed += new ExecutedRoutedEventHandler(cbNew_Executed);
            window.CommandBindings.Add(cbNew);

            //绑定OpenProject命令
            CommandBinding cbOpen = new CommandBinding();
            cbOpen.Command = AppCommands.OpenProject;
            cbOpen.CanExecute += new CanExecuteRoutedEventHandler(cbOpen_CanExecute);
            cbOpen.Executed += new ExecutedRoutedEventHandler(cbOpen_Executed);
            window.CommandBindings.Add(cbOpen);

            //绑定SaveProject命令
            CommandBinding cbSave = new CommandBinding();
            cbSave.Command = AppCommands.SaveProject;
            cbSave.CanExecute += new CanExecuteRoutedEventHandler(cbSave_CanExecute);
            cbSave.Executed += new ExecutedRoutedEventHandler(cbSave_Executed);
            window.CommandBindings.Add(cbSave);

            //绑定CloseProject命令
            CommandBinding cbClose = new CommandBinding();
            cbClose.Command = AppCommands.CloseProject;
            cbClose.CanExecute += new CanExecuteRoutedEventHandler(cbClose_CanExecute);
            cbClose.Executed += new ExecutedRoutedEventHandler(cbClose_Executed);
            window.CommandBindings.Add(cbClose);

            //配置网格
            CommandBinding cbConfigGrid = new CommandBinding();
            cbConfigGrid.Command = AppCommands.ConfigGrid;
            cbConfigGrid.Executed += new ExecutedRoutedEventHandler(cbConfigGrid_Executed);
            cbConfigGrid.CanExecute += new CanExecuteRoutedEventHandler(cbConfigGrid_CanExecute);
            window.CommandBindings.Add(cbConfigGrid);

            //运行ModFlow
            CommandBinding cbRunModflow = new CommandBinding();
            cbRunModflow.Command = AppCommands.RunModFlow;
            cbRunModflow.Executed += new ExecutedRoutedEventHandler(cbRunModflow_Executed);
            cbRunModflow.CanExecute += new CanExecuteRoutedEventHandler(cbRunModflow_CanExecute);
            window.CommandBindings.Add(cbRunModflow);

            //全局选项
            CommandBinding cbGlobalOption = new CommandBinding();
            cbGlobalOption.Command = AppCommands.GlobalOption;
            cbGlobalOption.Executed += new ExecutedRoutedEventHandler(cbGlobalOption_Executed);
            cbGlobalOption.CanExecute += new CanExecuteRoutedEventHandler(cbGlobalOption_CanExecute);
            window.CommandBindings.Add(cbGlobalOption);

            CommandBinding cbStressPeriod = new CommandBinding();
            cbStressPeriod.Command = AppCommands.StressPeriod;
            cbStressPeriod.Executed += new ExecutedRoutedEventHandler(cbStressPeriod_Executed);
            cbStressPeriod.CanExecute += new CanExecuteRoutedEventHandler(cbStressPeriod_CanExecute);
            window.CommandBindings.Add(cbStressPeriod);

            CommandBinding cbPackage = new CommandBinding();
            cbPackage.Command = AppCommands.Package;
            cbPackage.CanExecute += new CanExecuteRoutedEventHandler(cbPackage_CanExecute);
            cbPackage.Executed += new ExecutedRoutedEventHandler(cbPackage_Executed);
            window.CommandBindings.Add(cbPackage);

            CommandBinding cbUnit = new CommandBinding();
            cbUnit.Command = AppCommands.Unit;
            cbUnit.CanExecute += new CanExecuteRoutedEventHandler(cbUnit_CanExecute);
            cbUnit.Executed += new ExecutedRoutedEventHandler(cbUnit_Executed);
            window.CommandBindings.Add(cbUnit);

            CommandBinding cbIBound = new CommandBinding();
            cbIBound.Command = AppCommands.IBound;
            cbIBound.CanExecute += new CanExecuteRoutedEventHandler(cbIBound_CanExecute);
            cbIBound.Executed += new ExecutedRoutedEventHandler(cbIBound_Executed);
            window.CommandBindings.Add(cbIBound);

            CommandBinding cbStartHead = new CommandBinding();
            cbStartHead.Command = AppCommands.StartHead;
            cbStartHead.CanExecute += new CanExecuteRoutedEventHandler(cbStartHead_CanExecute);
            cbStartHead.Executed += new ExecutedRoutedEventHandler(cbStartHead_Executed);
            window.CommandBindings.Add(cbStartHead);

            CommandBinding cbTopElevation = new CommandBinding();
            cbTopElevation.Command = AppCommands.TopElevation;
            cbTopElevation.CanExecute += new CanExecuteRoutedEventHandler(cbTopElevation_CanExecute);
            cbTopElevation.Executed += new ExecutedRoutedEventHandler(cbTopElevation_Executed);
            window.CommandBindings.Add(cbTopElevation);

            CommandBinding cbBotElevation = new CommandBinding();
            cbBotElevation.Command = AppCommands.BotElevation;
            cbBotElevation.CanExecute += new CanExecuteRoutedEventHandler(cbBotElevation_CanExecute);
            cbBotElevation.Executed += new ExecutedRoutedEventHandler(cbBotElevation_Executed);
            window.CommandBindings.Add(cbBotElevation);

            CommandBinding cbConBed = new CommandBinding();
            cbConBed.Command = AppCommands.ConBed;
            cbConBed.CanExecute += new CanExecuteRoutedEventHandler(cbConBed_CanExecute);
            cbConBed.Executed += new ExecutedRoutedEventHandler(cbConBed_Executed);
            window.CommandBindings.Add(cbConBed);

            //输出控制
            CommandBinding cbOutputControl = new CommandBinding();
            cbOutputControl.Command = AppCommands.OutputControl;
            cbOutputControl.Executed += new ExecutedRoutedEventHandler(cbOutputControl_Executed);
            cbOutputControl.CanExecute += new CanExecuteRoutedEventHandler(cbOutputControl_CanExecute);
            window.CommandBindings.Add(cbOutputControl);

            //源汇项部分
            CommandBinding cbWellEdit = new CommandBinding();
            cbWellEdit.Command = AppCommands.WellEdit;
            cbWellEdit.Executed += new ExecutedRoutedEventHandler(cbWellEdit_Executed);
            cbWellEdit.CanExecute += new CanExecuteRoutedEventHandler(cbWellEdit_CanExecute);
            window.CommandBindings.Add(cbWellEdit);

            //三维部分相关的命令

            CommandBinding cbResetView = new CommandBinding();
            cbResetView.Command = AppCommands.ResetView;
            cbResetView.Executed += new ExecutedRoutedEventHandler(cbResetView_Executed);

            window.CommandBindings.Add(cbResetView);


            CommandBinding cbLPFEdit = new CommandBinding();
            cbLPFEdit.Command = AppCommands.LpfEdit;
            cbLPFEdit.Executed += new ExecutedRoutedEventHandler(cbLPFEdit_Executed);
            cbLPFEdit.CanExecute += new CanExecuteRoutedEventHandler(cbLPFEdit_CanExecute);
            window.CommandBindings.Add(cbLPFEdit);

            CommandBinding cbBCFEdit = new CommandBinding();
            cbBCFEdit.Command = AppCommands.BcfEdit;
            cbBCFEdit.Executed += new ExecutedRoutedEventHandler(cbBCFEdit_Executed);
            cbBCFEdit.CanExecute += new CanExecuteRoutedEventHandler(cbBCFEdit_CanExecute);
            window.CommandBindings.Add(cbBCFEdit);

            CommandBinding cbSIPEdit = new CommandBinding();
            cbSIPEdit.Command = AppCommands.SipEdit;
            cbSIPEdit.Executed += new ExecutedRoutedEventHandler(cbSIPEdit_Executed);
            cbSIPEdit.CanExecute += new CanExecuteRoutedEventHandler(cbSIPEdit_CanExecute);
            window.CommandBindings.Add(cbSIPEdit);

            CommandBinding cbPCGEdit = new CommandBinding();
            cbPCGEdit.Command = AppCommands.PcgEdit;
            cbPCGEdit.Executed += new ExecutedRoutedEventHandler(cbPCGEdit_Executed);
            cbPCGEdit.CanExecute += new CanExecuteRoutedEventHandler(cbPCGEdit_CanExecute);
            window.CommandBindings.Add(cbPCGEdit);

            CommandBinding cbDE4Edit = new CommandBinding();
            cbDE4Edit.Command = AppCommands.DE4Edit;
            cbDE4Edit.Executed += new ExecutedRoutedEventHandler(cbDE4Edit_Executed);
            cbDE4Edit.CanExecute += new CanExecuteRoutedEventHandler(cbDE4Edit_CanExecute);
            window.CommandBindings.Add(cbDE4Edit);

            CommandBinding cbTopView = new CommandBinding();
            cbTopView.Command = AppCommands.TopView;
            cbTopView.Executed += new ExecutedRoutedEventHandler(cbTopView_Executed);
            cbTopView.CanExecute += new CanExecuteRoutedEventHandler(cbTopView_CanExecute);
            window.CommandBindings.Add(cbTopView);

            CommandBinding cbFrontView = new CommandBinding();
            cbFrontView.Command = AppCommands.FrontView;
            cbFrontView.Executed += new ExecutedRoutedEventHandler(cbFrontView_Executed);
            cbFrontView.CanExecute += new CanExecuteRoutedEventHandler(cbFrontView_CanExecute);
            window.CommandBindings.Add(cbFrontView);

            CommandBinding cbRightView = new CommandBinding();
            cbRightView.Command = AppCommands.RightView;
            cbRightView.Executed += new ExecutedRoutedEventHandler(cbRightView_Executed);
            cbRightView.CanExecute += new CanExecuteRoutedEventHandler(cbRightView_CanExecute);
            window.CommandBindings.Add(cbRightView);

            CommandBinding cbCheckModflow = new CommandBinding();
            cbCheckModflow.Command = AppCommands.CheckModflow;
            cbCheckModflow.Executed += new ExecutedRoutedEventHandler(cbCheckModflow_Executed);
            cbCheckModflow.CanExecute += new CanExecuteRoutedEventHandler(cbCheckModflow_CanExecute);
            window.CommandBindings.Add(cbCheckModflow);



            CommandBinding cbConstantHeadEdit = new CommandBinding();
            cbConstantHeadEdit.Command = AppCommands.ConstantHeadEdit;
            cbConstantHeadEdit.Executed += new ExecutedRoutedEventHandler(cbConstantHeadEdit_Executed);
            cbConstantHeadEdit.CanExecute += new CanExecuteRoutedEventHandler(cbConstantHeadEdit_CanExecute);
            window.CommandBindings.Add(cbConstantHeadEdit);

            CommandBinding cbRiverEdit = new CommandBinding();
            cbRiverEdit.Command = AppCommands.RiverEdit;
            cbRiverEdit.CanExecute += new CanExecuteRoutedEventHandler(cbRiverEdit_CanExecute);
            cbRiverEdit.Executed += new ExecutedRoutedEventHandler(cbRiverEdit_Executed);
            window.CommandBindings.Add(cbRiverEdit);

            CommandBinding cbGneralHeadEdit = new CommandBinding();
            cbGneralHeadEdit.Command = AppCommands.GneralHeadEdit;
            cbGneralHeadEdit.Executed += new ExecutedRoutedEventHandler(cbGneralHeadEdit_Executed);
            cbGneralHeadEdit.CanExecute += new CanExecuteRoutedEventHandler(cbGneralHeadEdit_CanExecute);
            window.CommandBindings.Add(cbGneralHeadEdit);

            CommandBinding cbDrainEdit = new CommandBinding();
            cbDrainEdit.Command = AppCommands.DrainEdit;
            cbDrainEdit.CanExecute += new CanExecuteRoutedEventHandler(cbDrainEdit_CanExecute);
            cbDrainEdit.Executed += new ExecutedRoutedEventHandler(cbDrainEdit_Executed);
            window.CommandBindings.Add(cbDrainEdit);

            CommandBinding cbWallEdit = new CommandBinding();
            cbWallEdit.Command = AppCommands.WallEdit;
            cbWallEdit.CanExecute += new CanExecuteRoutedEventHandler(cbWallEdit_CanExecute);
            cbWallEdit.Executed += new ExecutedRoutedEventHandler(cbWallEdit_Executed);
            window.CommandBindings.Add(cbWallEdit);

            CommandBinding cbRechargeEdit = new CommandBinding();
            cbRechargeEdit.Command = AppCommands.RechargeEdit;
            cbRechargeEdit.CanExecute += new CanExecuteRoutedEventHandler(cbRechargeEdit_CanExecute);
            cbRechargeEdit.Executed += new ExecutedRoutedEventHandler(cbRechargeEdit_Executed);
            window.CommandBindings.Add(cbRechargeEdit);

            CommandBinding cbEvapostransEdit = new CommandBinding();
            cbEvapostransEdit.Command = AppCommands.EvapostransEdit;
            cbEvapostransEdit.CanExecute += new CanExecuteRoutedEventHandler(cbEvapostransEdit_CanExecute);
            cbEvapostransEdit.Executed += new ExecutedRoutedEventHandler(cbEvapostransEdit_Executed);
            window.CommandBindings.Add(cbEvapostransEdit);

            CommandBinding cbDisplayOption = new CommandBinding();
            cbDisplayOption.Command = AppCommands.DisplayOption;
            cbDisplayOption.CanExecute += new CanExecuteRoutedEventHandler(cbDisplayOption_CanExecute);
            cbDisplayOption.Executed += new ExecutedRoutedEventHandler(cbDisplayOption_Executed);
            window.CommandBindings.Add(cbDisplayOption);

            CommandBinding cbInterpolatinOption = new CommandBinding();
            cbInterpolatinOption.Command = AppCommands.InterpolatinOption;
            cbInterpolatinOption.CanExecute += new CanExecuteRoutedEventHandler(cbInterpolatinOption_CanExecute);
            cbInterpolatinOption.Executed += new ExecutedRoutedEventHandler(cbInterpolatinOption_Executed);
            window.CommandBindings.Add(cbInterpolatinOption);


            CommandBinding cbOpenProjectWithName = new CommandBinding();
            cbOpenProjectWithName.Command = AppCommands.OpenProjectWithName;
            cbOpenProjectWithName.CanExecute += new CanExecuteRoutedEventHandler(cbOpenProjectWithName_CanExecute);
            cbOpenProjectWithName.Executed += new ExecutedRoutedEventHandler(cbOpenProjectWithName_Executed);
            window.CommandBindings.Add(cbOpenProjectWithName);

            CommandBinding cbUzfEdit = new CommandBinding();
            cbUzfEdit.Command = AppCommands.UzfEdit;
            cbUzfEdit.Executed += new ExecutedRoutedEventHandler(cbUzfEdit_Executed);
            cbUzfEdit.CanExecute += new CanExecuteRoutedEventHandler(cbUzfEdit_CanExecute);
            window.CommandBindings.Add(cbUzfEdit);




            //布局相关

            CommandBinding cbResetLayout = new CommandBinding();
            cbResetLayout.Command = AppCommands.ResetLayout;
            cbResetLayout.Executed += new ExecutedRoutedEventHandler(cbResetLayout_Executed);
            cbResetLayout.CanExecute += new CanExecuteRoutedEventHandler(cbResetLayout_CanExecute);
            window.CommandBindings.Add(cbResetLayout);


            //帮助信息
            CommandBinding cbHelp = new CommandBinding();
            cbHelp.Command = AppCommands.HelpInformation;
            cbHelp.Executed += new ExecutedRoutedEventHandler(cbHelp_Executed);
            cbHelp.CanExecute += new CanExecuteRoutedEventHandler(cbHelp_CanExecute);
            window.CommandBindings.Add(cbHelp);

            CommandBinding cbAbout = new CommandBinding();
            cbAbout.Command = AppCommands.AbutInformation;
            cbAbout.Executed += new ExecutedRoutedEventHandler(cbAbout_Executed);
            cbAbout.CanExecute += new CanExecuteRoutedEventHandler(cbAbout_CanExecute);
            window.CommandBindings.Add(cbAbout);
        }

        void cbAbout_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
        }

        void cbAbout_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            HA.ModFlow.Controls.Windows.About.winAbout win = new Controls.Windows.About.winAbout();
            win.Owner = mainWindow;
            win.ShowDialog();
        }

        void cbHelp_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
        }

        [DllImport("shell32.dll ")]
        private static extern void ShellExecute(IntPtr hwnd, StringBuilder lpszOp, StringBuilder lpszFile, StringBuilder lpszParams, StringBuilder lpszDir, int FsShowCmd);
        void cbHelp_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            string path = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
            ShellExecute(IntPtr.Zero, new StringBuilder("Open"), new StringBuilder("NoiseSystem.chm"), new StringBuilder(" "), new StringBuilder(path), 1);
        }


        void cbStressPeriod_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            List<StressPeriod> _stressPeriods = new List<StressPeriod>();
            foreach (StressPeriod item in ProjectService.DefaultService.Project.MfData.StressPeriods.InnerList)
            {
                _stressPeriods.Add((StressPeriod)item.Clone());
            }

            winStressPeriod winSPeriond = new winStressPeriod(_stressPeriods, ProjectService.DefaultService.Project.MfData.ModelOption.Units);
            winSPeriond.Owner = mainWindow;
            winSPeriond.ResizeMode = ResizeMode.NoResize;
            winSPeriond.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            winSPeriond.ShowDialog();
            if (winSPeriond.DialogResult == true)
            {
                ProjectService.DefaultService.Project.MfData.StressPeriods.ResetStressPeriods(winSPeriond.StressPeriod);
            }
        }

        void cbStressPeriod_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.DefaultService.BNullProj)
            {
                if (ProjectService.DefaultService.Project.MfData != null)
                {
                    e.CanExecute = true;
                    e.Handled = true;
                }
            }
        }

        void cbPackage_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            winPackages winPackages = new winPackages(ProjectService.DefaultService.Project.MfData.ModelOption, ProjectService.DefaultService.Project.MfData);
            winPackages.Owner = mainWindow;
            winPackages.ResizeMode = ResizeMode.NoResize;
            winPackages.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            winPackages.ShowDialog();
        }

        void cbPackage_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.DefaultService.BNullProj)
            {
                if (ProjectService.DefaultService.Project.MfData != null)
                {
                    e.CanExecute = true;
                    e.Handled = true;
                }
            }
        }

        void cbUnit_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            winUnits winUnits = new winUnits(ProjectService.DefaultService.Project.MfData.ModelOption);
            winUnits.Owner = mainWindow;
            winUnits.ResizeMode = ResizeMode.NoResize;
            winUnits.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            winUnits.ShowDialog();
            if (winUnits.DialogResult == true)
            {
                ProjectService.DefaultService.Project.MfData.ModelOption.Units.Length = winUnits.MdOption.Units.Length;
                ProjectService.DefaultService.Project.MfData.ModelOption.Units.Time = winUnits.MdOption.Units.Time;
            }
        }

        void cbUnit_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.DefaultService.BNullProj)
            {
                if (ProjectService.DefaultService.Project.MfData != null)
                {
                    e.CanExecute = true;
                    e.Handled = true;
                }
            }
        }


        void cbIBound_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            winCellCenterDSEdit win = new winCellCenterDSEdit(ProjectService.DefaultService.Project.MfData.GridData.GetIBoundDs(), ProjectService.DefaultService.Project);
            win.Owner = mainWindow;
            win.ResizeMode = ResizeMode.NoResize;
            win.Unit += "无量纲";
            win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            if (win.ShowDialog() == true)
            {

                ProjectService.DefaultService.Project.MfData.GridData.SetIBoundDs(win.PcDs.Dataset);

                if (ProjectService.DefaultService.Project.CurrentDSData!=null&&ProjectService.DefaultService.Project.CurrentDSData.Label == win.PcDs.Dataset.Label)
                    ProjectService.DefaultService.Project.CurrentDSData = ProjectService.DefaultService.Project.MfData.GridData.GetIBoundDs();
            }
        }

        void cbIBound_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.DefaultService.BNullProj)
            {
                if (ProjectService.DefaultService.Project.MfData != null)
                {
                    e.CanExecute = true;
                    e.Handled = true;
                }
            }
        }

        void cbStartHead_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            winCellCenterDSEdit win = new winCellCenterDSEdit(ProjectService.DefaultService.Project.MfData.GridData.GetIHeadDs(), ProjectService.DefaultService.Project);
            win.Owner = mainWindow;
            win.ResizeMode = ResizeMode.NoResize;
            win.Unit += "(" + Domain.DomainLayer.UnitConverter.GetLength(ProjectService.DefaultService.Project.MfData.ModelOption.Units.Length) + ")";
            win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            if (win.ShowDialog() == true)
            {

                ProjectService.DefaultService.Project.MfData.GridData.SetIHeadDs(win.PcDs.Dataset);
                if (ProjectService.DefaultService.Project.CurrentDSData != null && ProjectService.DefaultService.Project.CurrentDSData.Label == win.PcDs.Dataset.Label)
                    ProjectService.DefaultService.Project.CurrentDSData = ProjectService.DefaultService.Project.MfData.GridData.GetIHeadDs();

            }
        }

        void cbStartHead_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.DefaultService.BNullProj)
            {
                if (ProjectService.DefaultService.Project.MfData != null)
                {
                    e.CanExecute = true;
                    e.Handled = true;
                }
            }
        }

        void cbTopElevation_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            winCellCenterDSEdit win = new winCellCenterDSEdit(ProjectService.DefaultService.Project.MfData.GridData.GetTopElevationDs(), ProjectService.DefaultService.Project);
            win.Owner = mainWindow;
            win.ResizeMode = ResizeMode.NoResize;
            win.Unit += "(" + Domain.DomainLayer.UnitConverter.GetLength(ProjectService.DefaultService.Project.MfData.ModelOption.Units.Length) + ")";
            win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            if (win.ShowDialog() == true)
            {

                ProjectService.DefaultService.Project.MfData.GridData.SetTopElevationDS(win.PcDs.Dataset);
                if (ProjectService.DefaultService.Project.CurrentDSData != null && ProjectService.DefaultService.Project.CurrentDSData.Label == win.PcDs.Dataset.Label)
                    ProjectService.DefaultService.Project.CurrentDSData = ProjectService.DefaultService.Project.MfData.GridData.GetTopElevationDs();

            }
        }

        void cbTopElevation_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.DefaultService.BNullProj)
            {
                if (ProjectService.DefaultService.Project.MfData != null)
                {
                    e.CanExecute = true;
                    e.Handled = true;
                }
            }
        }

        void cbBotElevation_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            winCellCenterDSEdit win = new winCellCenterDSEdit(ProjectService.DefaultService.Project.MfData.GridData.GetBotElevationDs(), ProjectService.DefaultService.Project);
            win.Owner = mainWindow;
            win.ResizeMode = ResizeMode.NoResize;
            win.Unit += "(" + Domain.DomainLayer.UnitConverter.GetLength(ProjectService.DefaultService.Project.MfData.ModelOption.Units.Length) + ")";
            win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            if (win.ShowDialog() == true)
            {

                ProjectService.DefaultService.Project.MfData.GridData.SetBotElevationDS(win.PcDs.Dataset);
                if (ProjectService.DefaultService.Project.CurrentDSData != null && ProjectService.DefaultService.Project.CurrentDSData.Label == win.PcDs.Dataset.Label)
                    ProjectService.DefaultService.Project.CurrentDSData = ProjectService.DefaultService.Project.MfData.GridData.GetBotElevationDs();

            }
        }

        void cbBotElevation_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.DefaultService.BNullProj)
            {
                if (ProjectService.DefaultService.Project.MfData != null)
                {
                    e.CanExecute = true;
                    e.Handled = true;
                }
            }
        }

        void cbConBed_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            winConfiningBed winConfiningBed = new winConfiningBed(ProjectService.DefaultService.Project);
            winConfiningBed.Owner = mainWindow;
            winConfiningBed.ResizeMode = ResizeMode.NoResize;
            winConfiningBed.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            winConfiningBed.ShowInTaskbar = false;
            winConfiningBed.ShowDialog();
        }

        void cbConBed_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.DefaultService.BNullProj)
            {
                if (ProjectService.DefaultService.Project.MfData != null)
                {
                    e.CanExecute = true;
                    e.Handled = true;
                }
            }
        }

        void cbResetLayout_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
        }

        void cbResetLayout_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            try
            {
                UIModule.DefaultModule.RibbonV2ViewModel.ViewOpViewModel.View2D = true;
                UIModule.DefaultModule.RendererViewModel.View2D = UIModule.DefaultModule.RibbonV2ViewModel.ViewOpViewModel.View2D;
            }
            catch { }//捕获空指针异常
            System.IO.StringReader sr = new System.IO.StringReader(ConfigService.DefaultService.SettingInfo.DefaultLayoutString);


            UIModule.DefaultModule.DockingManager.RestoreLayout(sr);

            UIModule.DefaultModule.DocumentContent.Show();


        }

        void cbUzfEdit_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.DefaultService.BNullProj)
            {
                if (ProjectService.DefaultService.Project.MfData != null)
                {
                    if (ProjectService.DefaultService.Project.MfData.SourceSinks != null)
                    {
                        if (ProjectService.DefaultService.Project.MfData.SourceSinks.UzfCollection != null)
                        {
                            if (ProjectService.DefaultService.Project.MfData.SourceSinks.UzfCollection.Enabled)
                            {
                                e.CanExecute = true;
                                e.Handled = true;
                            }
                        }
                    }
                }
            }
        }

        void cbUzfEdit_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            HA.ModFlow.Controls.Windows.SourceSinks.winUzfPage win = new Controls.Windows.SourceSinks.winUzfPage(ProjectService.DefaultService.Project.MfData);
            win.Owner = mainWindow;
            if (win.ShowDialog().Value)
            {

            }
        }

        void cbOpenProjectWithName_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            string name = e.Parameter as string;

            ApplicationService.DefalutService.OpenProject(name);

        }

        void cbOpenProjectWithName_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {

            e.CanExecute = true;
        }



        void cbRunModflow_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.DefaultService.BNullProj)
            {
                if (ProjectService.DefaultService.Project.MfData != null)
                {
                    e.CanExecute = true;
                    e.Handled = true;
                }

            }

        }



        void cbGlobalOption_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.DefaultService.BNullProj)
            {
                if (ProjectService.DefaultService.Project.MfData != null)
                {
                    e.CanExecute = true;
                    e.Handled = true;
                }

            }
        }

        void cbConfigGrid_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.DefaultService.BNullProj)
            {
                if (ProjectService.DefaultService.Project.MfData != null)
                {
                    e.CanExecute = true;
                    e.Handled = true;
                }

            }
        }

        void cbWellEdit_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.DefaultService.BNullProj)
            {
                if (ProjectService.DefaultService.Project.MfData != null)
                {
                    if (ProjectService.DefaultService.Project.MfData.SourceSinks.Wells.Enabled)
                    {
                        e.CanExecute = true;
                        e.Handled = true;
                    }
                }

            }
        }

        void cbOutputControl_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.DefaultService.BNullProj)
            {
                if (ProjectService.DefaultService.Project.MfData != null)
                {
                    e.CanExecute = true;
                    e.Handled = true;
                }

            }
        }

        void cbInterpolatinOption_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            throw new NotImplementedException();
        }

        void cbInterpolatinOption_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.DefaultService.BNullProj)
            {
                if (ProjectService.DefaultService.Project.MfData != null)
                {
                    e.CanExecute = true;
                    e.Handled = true;
                }

            }
        }

        void cbDisplayOption_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            //HA.ModFlow.Controls.Windows.DisplayOptions.winDisplayOption option = new Controls.Windows.DisplayOptions.winDisplayOption(ProjectSerivce.DefaultService.Project.DisplayOption, ProjectSerivce.DefaultService.Project.Grid3dData.MainGrid);// new HA.ModFlow.Controls.Windows.DisplayOptions.winDisplayOption(ProjectSerivce.DefaultService.Project.DisplayOption,ProjectSerivce.DefaultService.Project.Grid3dData.MainGrid);
            //option.Owner = mainWindow;         
            //option.ResizeMode = ResizeMode.NoResize;
            //option.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            //if (option.ShowDialog().Value)
            //{               
            //    ProjectSerivce.DefaultService.Project.DisplayOption.ResetDisplayOption(option.DisplayOptions);
            //}

            ProjectService.DefaultService.Project.DisplayOption2.UpdateDataState(ProjectService.DefaultService.Project);
            HA.ModFlow.Controls.Windows.DisplayOptions.winDisplayOptionV2 option = new Controls.Windows.DisplayOptions.winDisplayOptionV2(ProjectService.DefaultService.Project.DisplayOption2, ProjectService.DefaultService.Project.Grid3dData.MainGrid); ;// new HA.ModFlow.Controls.Windows.DisplayOptions.winDisplayOption(ProjectSerivce.DefaultService.Project.DisplayOption,ProjectSerivce.DefaultService.Project.Grid3dData.MainGrid);
            option.Owner = mainWindow;
            option.ResizeMode = ResizeMode.NoResize;
            option.WindowStartupLocation = WindowStartupLocation.CenterScreen;

            if (option.ShowDialog().Value)
            {
                //ProjectSerivce.DefaultService.Project.DisplayOption.ResetDisplayOption(option.DisplayOptions);
                ProjectService.DefaultService.Project.DisplayOption2.ResetDataAndTriggerEvent(option.DisplayOptions);
            }

        }

        void cbDisplayOption_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.DefaultService.BNullProj)
            {
                e.CanExecute = true;
                e.Handled = true;
            }

        }

        void cbEvapostransEdit_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            winEVT evts = new winEVT(ProjectService.DefaultService.Project.MfData);
            evts.Owner = mainWindow;
            evts.ResizeMode = ResizeMode.NoResize;
            evts.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            evts.ShowDialog();
        }

        void cbEvapostransEdit_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.DefaultService.BNullProj)
            {
                if (ProjectService.DefaultService.Project.MfData != null)
                {
                    if (ProjectService.DefaultService.Project.MfData.SourceSinks.Evts.Enabled)
                    {
                        e.CanExecute = true;
                        e.Handled = true;
                    }
                }
            }
        }

        void cbRechargeEdit_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            winRecharge recharge = new winRecharge(ProjectService.DefaultService.Project.MfData);
            recharge.Owner = mainWindow;
            recharge.ResizeMode = ResizeMode.NoResize;
            recharge.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            recharge.ShowDialog();
        }

        void cbRechargeEdit_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.DefaultService.BNullProj)
            {
                if (ProjectService.DefaultService.Project.MfData != null)
                {
                    if (ProjectService.DefaultService.Project.MfData.SourceSinks.Recharges.Enabled)
                    {
                        e.CanExecute = true;
                        e.Handled = true;
                    }
                }
            }
        }

        void cbWallEdit_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            winHorizontalFlowBarrier win = new winHorizontalFlowBarrier(ProjectService.DefaultService.Project.MfData.HfbData.HfbList, ProjectService.DefaultService.Project.MfData.GridData);
            win.Owner = mainWindow;
            win.ResizeMode = ResizeMode.NoResize;
            win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            if (win.ShowDialog().Value)
            {
                ProjectService.DefaultService.Project.MfData.HfbData.ResetHFBDatas(win.Hfbs);
            }
        }

        void cbWallEdit_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.DefaultService.BNullProj)
            {
                if (ProjectService.DefaultService.Project.MfData != null)
                {
                    if (ProjectService.DefaultService.Project.MfData.HfbData.Enabled && ProjectService.DefaultService.Project.MfData.HfbData.HfbList.Count > 0)
                    {
                        e.CanExecute = true;
                        e.Handled = true;
                    }
                }

            }
        }

        void cbDrainEdit_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            winDrainPack win = new winDrainPack(ProjectService.DefaultService.Project.MfData);
            win.Owner = mainWindow;
            win.ResizeMode = ResizeMode.NoResize;
            win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            win.ShowDialog();
        }

        void cbDrainEdit_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.DefaultService.BNullProj)
            {
                if (ProjectService.DefaultService.Project.MfData != null)
                {
                    if (ProjectService.DefaultService.Project.MfData.SourceSinks.Drains.Enabled)
                    {
                        e.CanExecute = true;
                        e.Handled = true;
                    }
                }
            }
        }

        void cbGneralHeadEdit_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.DefaultService.BNullProj)
            {
                if (ProjectService.DefaultService.Project.MfData != null)
                {
                    if (ProjectService.DefaultService.Project.MfData.SourceSinks.GeneralHeads.Enabled)
                    {
                        e.CanExecute = true;
                        e.Handled = true;
                    }
                }
            }
        }

        void cbGneralHeadEdit_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            winGHBPack win = new winGHBPack(ProjectService.DefaultService.Project.MfData);
            win.Owner = mainWindow;
            win.ResizeMode = ResizeMode.NoResize;
            win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            win.ShowDialog();
        }

        void cbRiverEdit_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            winRiverPack win = new winRiverPack(ProjectService.DefaultService.Project.MfData);
            win.Owner = mainWindow;
            win.ResizeMode = ResizeMode.NoResize;
            win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            win.ShowDialog();
        }

        void cbRiverEdit_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.DefaultService.BNullProj)
            {
                if (ProjectService.DefaultService.Project.MfData != null)
                {
                    if (ProjectService.DefaultService.Project.MfData.SourceSinks.Rivers.Enabled)
                    {
                        e.CanExecute = true;
                        e.Handled = true;
                    }
                }
            }
        }

        void cbConstantHeadEdit_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.DefaultService.BNullProj)
            {
                if (ProjectService.DefaultService.Project.MfData != null)
                {
                    if (ProjectService.DefaultService.Project.MfData.SourceSinks.SpecifiedHeads.Enabled)
                    {
                        e.CanExecute = true;
                        e.Handled = true;
                    }
                }
            }
        }

        void cbConstantHeadEdit_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            winSpecifiedHeadPack win = new winSpecifiedHeadPack(ProjectService.DefaultService.Project.MfData);
            win.Owner = mainWindow;
            win.ResizeMode = ResizeMode.NoResize;
            win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            win.ShowDialog();
        }



        void cbCheckModflow_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.DefaultService.BNullProj)
            {
                if (ProjectService.DefaultService.Project.MfData != null)
                {
                    e.CanExecute = true;
                    e.Handled = true;
                }
            }
        }


        void cbCheckModflow_Executed(object sender, ExecutedRoutedEventArgs e)
        {

            HA.ModFlow.Controls.Windows.DataOperation.winModelChecker win = new Controls.Windows.DataOperation.winModelChecker(ProjectService.DefaultService.Project);//, CheckModelType.ModflowSimulation);
            win.Owner = mainWindow;
            win.ResizeMode = ResizeMode.NoResize;
            win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            win.ShowDialog();
            ProjectService.DefaultService.Project.MfData.GridData.AskElevationChanged();
        }

        void cbRightView_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = !ProjectService.DefaultService.BNullProj;
            e.Handled = true;
        }

        void cbRightView_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            if (UIModule.DefaultModule.RibbonV2ViewModel.ViewOpViewModel.MinGridVM != null)
            {
                UIModule.DefaultModule.RibbonV2ViewModel.ViewOpViewModel.MinGridVM.ViewMode = HA.Data.ProjectViewType.RIGHT;

            }

            //Render3dModule.DefaultModule.SetView(HAVTKPack.VIEWTYPE.RIGHT);
            //GisModule.DefaultModule.GisManager.VIEWMODE=HAGISV2.FMAPVIEW.RIGHT;
        }

        void cbFrontView_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {


            e.CanExecute = !ProjectService.DefaultService.BNullProj;
            e.Handled = true;
        }

        void cbFrontView_Executed(object sender, ExecutedRoutedEventArgs e)
        {

            if (UIModule.DefaultModule.RibbonV2ViewModel.ViewOpViewModel.MinGridVM != null)
            {
                UIModule.DefaultModule.RibbonV2ViewModel.ViewOpViewModel.MinGridVM.ViewMode = HA.Data.ProjectViewType.FRONT;

            }
            //Render3dModule.DefaultModule.SetView(HAVTKPack.VIEWTYPE.FRONT);
            //GisModule.DefaultModule.GisManager.VIEWMODE = HAGISV2.FMAPVIEW.FRONT;
        }

        void cbTopView_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = !ProjectService.DefaultService.BNullProj;
            e.Handled = true;
        }

        void cbTopView_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            if (UIModule.DefaultModule.RibbonV2ViewModel.ViewOpViewModel.MinGridVM != null)
            {
                UIModule.DefaultModule.RibbonV2ViewModel.ViewOpViewModel.MinGridVM.ViewMode = HA.Data.ProjectViewType.TOP;

            }

            //Render3dModule.DefaultModule.SetView(HAVTKPack.VIEWTYPE.TOP);
            //GisModule.DefaultModule.GisManager.VIEWMODE = HAGISV2.FMAPVIEW.NORMAL;
        }

        void cbDE4Edit_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.DefaultService.BNullProj)
            {
                if (ProjectService.DefaultService.Project.MfData != null)
                {
                    if (ProjectService.DefaultService.Project.MfData.ModelOption.SolverPack == SOLVERPACK.DE4)
                    {
                        e.CanExecute = true;
                        e.Handled = true;
                    }
                }
            }
        }

        void cbDE4Edit_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            winDE4 WinDE = new winDE4(ProjectService.DefaultService.Project.MfData.DESolver);
            WinDE.Owner = mainWindow;
            WinDE.ResizeMode = ResizeMode.NoResize;
            WinDE.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            if (WinDE.ShowDialog().Value)
            {
                ProjectService.DefaultService.Project.MfData.DESolver = WinDE.Des;
            }
        }

        void cbPCGEdit_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.DefaultService.BNullProj)
            {
                if (ProjectService.DefaultService.Project.MfData != null)
                {
                    if (ProjectService.DefaultService.Project.MfData.ModelOption.SolverPack == SOLVERPACK.PCG)
                    {
                        e.CanExecute = true;
                        e.Handled = true;
                    }
                }
            }
        }

        void cbPCGEdit_Executed(object sender, ExecutedRoutedEventArgs e)
        {

            winPCGSolver Wpcg = new winPCGSolver(ProjectService.DefaultService.Project.MfData.PcgSolver);
            Wpcg.Owner = mainWindow;
            Wpcg.ResizeMode = ResizeMode.NoResize;
            Wpcg.WaterHeadLabel += "(" + Domain.DomainLayer.UnitConverter.GetLength(ProjectService.DefaultService.Project.MfData.ModelOption.Units.Length) + "):";
            Wpcg.ResidualLabel += "(" + Domain.DomainLayer.UnitConverter.GetLength(ProjectService.DefaultService.Project.MfData.ModelOption.Units.Length) + "^3/" + Domain.DomainLayer.UnitConverter.GetTime(ProjectService.DefaultService.Project.MfData.ModelOption.Units.Time) + "):";
            Wpcg.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            if (Wpcg.ShowDialog().Value)
            {
                ProjectService.DefaultService.Project.MfData.PcgSolver = Wpcg.PCGsol;
            }


        }

        void cbSIPEdit_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.DefaultService.BNullProj)
            {
                if (ProjectService.DefaultService.Project.MfData != null)
                {
                    if (ProjectService.DefaultService.Project.MfData.ModelOption.SolverPack == SOLVERPACK.SIP)
                    {
                        e.CanExecute = true;
                        e.Handled = true;
                    }
                }
            }
        }

        void cbSIPEdit_Executed(object sender, ExecutedRoutedEventArgs e)
        {


            winSIPConfig Wsip = new winSIPConfig(ProjectService.DefaultService.Project.MfData);
            Wsip.Owner = mainWindow;
            Wsip.ResizeMode = ResizeMode.NoResize;
            Wsip.WindowStartupLocation = WindowStartupLocation.CenterScreen;

            if (Wsip.ShowDialog() == true)
            {
                ProjectService.DefaultService.Project.MfData.SipSolver = Wsip.SipSolver;

            }


        }

        void cbBCFEdit_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.DefaultService.BNullProj)
            {
                if (ProjectService.DefaultService.Project.MfData != null)
                {
                    if (ProjectService.DefaultService.Project.MfData.ModelOption.InnerPack == INNERPACK.BCF)
                    {
                        e.CanExecute = true;
                        e.Handled = true;
                    }
                }
            }
        }

        void cbBCFEdit_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            //WindowService.DefaultService.ShowDialog(ConstNames.BCFP );

            HA.ModFlow.Controls.Windows.InternalFlow.winBCFFlow win = new Controls.Windows.InternalFlow.winBCFFlow(ProjectService.DefaultService.Project);
            win.Owner = mainWindow;
            win.ResizeMode = ResizeMode.NoResize;
            win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            if (win.ShowDialog().Value)
            {
                //在窗体确定时随数据一起调用 在此不需触发
                //ProjectSerivce.DefaultService.Project.MfData.FlowData.BcfData.OnBCFDataChanged();
            }


        }

        void cbLPFEdit_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.DefaultService.BNullProj)
            {
                if (ProjectService.DefaultService.Project.MfData != null)
                {
                    if (ProjectService.DefaultService.Project.MfData.ModelOption.InnerPack == INNERPACK.LPF)
                    {
                        e.CanExecute = true;
                        e.Handled = true;
                    }
                }
            }
        }

        void cbLPFEdit_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            //WindowService.DefaultService.ShowDialog(ConstNames.LPF );


            HA.ModFlow.Controls.Windows.InternalFlow.winLPFFlow win = new Controls.Windows.InternalFlow.winLPFFlow(ProjectService.DefaultService.Project);
            bool b = false;
            foreach (HA.ModFlow.Domain.DomainLayer.GridLayer item in ProjectService.DefaultService.Project.MfData.GridData.WaterGrid.Layers)
            {
                if (item.IsHaveConfiningBed)
                {
                    b = true;
                    break;
                }
            }
            win.isVkcb = b;
            win.Owner = mainWindow;
            win.ResizeMode = ResizeMode.NoResize;
            win.WindowStartupLocation = WindowStartupLocation.CenterScreen;


            if (win.ShowDialog().Value)
            {
                //在窗体确定时随数据一起调用 在此不需触发
                //ProjectSerivce.DefaultService.Project.MfData.FlowData.LpfData.OnLPFDataChanged();

            }


        }

        void cbResetView_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            Render3dModule.DefaultModule.ResetView();
        }

        void cbRunModflow_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            DosRun.ModFlowSolution solution = new DosRun.ModFlowSolution();

            DosRun.SolutionRunObject runObj = new DosRun.SolutionRunObject(solution);

            winRunSystem runWin = new winRunSystem();
            runWin.RunSystem.AddRunInstance(runObj);

            runWin.Owner = mainWindow;
            runWin.ResizeMode = ResizeMode.NoResize;
            runWin.WindowStartupLocation = WindowStartupLocation.CenterScreen;

            runWin.ShowDialog();

            //如果确定执行了计算
            if (runWin.IsHaveRun)
            {


                //读取结果数据

                DataOperationModule.DefaultModule.ReadModflowResult();








            }


        }

        /// <summary>
        /// 点击配置网格时运行此代码
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void cbConfigGrid_Executed(object sender, ExecutedRoutedEventArgs e)
        {



            winConfiningBed wcb = new winConfiningBed(ProjectService.DefaultService.Project);
            wcb.Owner = mainWindow;
            wcb.ResizeMode = ResizeMode.NoResize;
            wcb.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            if (wcb.ShowDialog().Value)
            {
                //ProjectSerivce.DefaultService.Project.MfData.GridData.WaterGrid
            }


        }


        void cbGlobalOption_Executed(object sender, ExecutedRoutedEventArgs e)
        {

            winGlobalOption winglob = new winGlobalOption(ProjectService.DefaultService.Project);
            winglob.Owner = mainWindow;
            winglob.ResizeMode = ResizeMode.NoResize;
            winglob.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            winglob.ShowDialog();

        }


        void cbOutputControl_Executed(object sender, ExecutedRoutedEventArgs e)
        {

            winOutputControl woc = new winOutputControl(ProjectService.DefaultService.Project.MfData.OutputCon);
            woc.Owner = mainWindow;
            woc.ResizeMode = ResizeMode.NoResize;
            woc.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            if (woc.ShowDialog().Value)
            {

            }


        }

        void cbWellEdit_Executed(object sender, ExecutedRoutedEventArgs e)
        {

            HA.ModFlow.Controls.Windows.SourceSinks.winWellPack wwp = new HA.ModFlow.Controls.Windows.SourceSinks.winWellPack(ProjectService.DefaultService.Project.MfData);
            wwp.Owner = mainWindow;
            wwp.ResizeMode = ResizeMode.NoResize;
            wwp.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            wwp.ShowDialog();

        }

        public void BindKeyToWindow(Window window)
        {

            KeyBinding kb_new = new KeyBinding(AppCommands.NewProject, Key.N, ModifierKeys.Control);
            KeyBinding kb_save = new KeyBinding(AppCommands.SaveProject, Key.S, ModifierKeys.Control);
            KeyBinding kb_open = new KeyBinding(AppCommands.OpenProject, Key.O, ModifierKeys.Control);
            //KeyBinding kb_close = new KeyBinding(AppCommands.CloseProject, Key.C, ModifierKeys.Control);

            window.InputBindings.Add(kb_new);
            window.InputBindings.Add(kb_save);
            window.InputBindings.Add(kb_open);
           // window.InputBindings.Add(kb_close);


            KeyBinding kb_diplayOption = new KeyBinding(AppCommands.DisplayOption, Key.D, ModifierKeys.Control);

            window.InputBindings.Add(kb_diplayOption);




        }

        static void cbNew_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            ApplicationService.DefalutService.NewProject();
        }

        static void cbNew_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
            e.Handled = true;
        }

        static void cbSave_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            ApplicationService.DefalutService.SaveProject();
        }

        static void cbSave_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.DefaultService.BNullProj)
            {
                e.CanExecute = true;
                e.Handled = true;

            }
        }
        static void cbOpen_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            ApplicationService.DefalutService.OpenProject();
        }

        static void cbOpen_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
            e.Handled = true;
        }

        static void cbClose_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            ApplicationService.DefalutService.CloseProject();
        }

        static void cbClose_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.DefaultService.BNullProj)
            {
                e.CanExecute = true;
                e.Handled = true;
            }

        }



    }
}
